package com.ucvisitorsapp.ui;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

import com.example.ucvisitorsapp.R;
import com.ucvisitorsapp.dao.BuildingDAOStub;
import com.ucvisitorsapp.dao.IBuildingDAO;

public class SearchScreen extends Activity {
	
	//create a variable for the interface
	private IBuildingDAO buildingDAO;
	
	 @Override
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.searchscreen);
	        
	        //link up the text view to a variable
	        AutoCompleteTextView actBuildingName = (AutoCompleteTextView) findViewById(R.id.autoComplete);
	        
	        //set the interface to an instance of the stub class
	        buildingDAO = new BuildingDAOStub();
	        
	        try {
				//get a list of building names.
				List<String> buildingNames = buildingDAO.fetchBuildingNames();
				
				//create an ArrayAdapter
				ArrayAdapter<String> aaBuildingNames = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, buildingNames);
				
				//link up the adapter and the ac text view
				actBuildingName.setAdapter(aaBuildingNames);
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    }


	    @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	        // Inflate the menu; this adds items to the action bar if it is present.
	        getMenuInflater().inflate(R.menu.main, menu);
	        return true;
	    }
	    
	    @Override
	    public boolean onOptionsItemSelected(MenuItem item) {
	        // Handle item selection
	        switch (item.getItemId()) {
	            case R.id.search_menuitem:
	            	//Intent intent = new Intent(this, MainActivity.class);;
	                return true;
	            case R.id.map_menuitem:
	            	Intent intent = new Intent(this, MapScreen.class);
	            	this.startActivity(intent);
	            	this.finish();	            	
	            	return true;
	            default:
	                return super.onOptionsItemSelected(item);
	        }
	    }

}
